from flask import Blueprint, request, jsonify
from flask_jwt_extended import jwt_required, get_jwt_identity
from controllers.auth_controller import AuthController

auth_bp = Blueprint('auth', __name__)

@auth_bp.route('/register', methods=['POST'])
def register():
    data = request.get_json()
    result = AuthController.register(data)
    return jsonify(result)

@auth_bp.route('/login', methods=['POST'])
def login():
    data = request.get_json()
    result = AuthController.login(data)
    return jsonify(result)

@auth_bp.route('/update', methods=['PUT'])
@jwt_required()
def update_user():
    current_user = get_jwt_identity()
    user_id = int(current_user)
    data = request.get_json()
    result = AuthController.update_user(user_id, data)
    return jsonify(result)

@auth_bp.route('/password', methods=['PUT'])
@jwt_required()
def change_password():
    current_user = get_jwt_identity()
    user_id = int(current_user)
    data = request.get_json()
    result = AuthController.change_password(user_id, data)
    return jsonify(result) 